package com.eastedu.controller;

import com.eastedu.domain.ObjectValueModel;
import com.eastedu.model.RequestParameter;
import com.eastedu.superise.handler.basic.*;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 袁松明
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/basic/data-update")
public class BasicResourceDataUpdateController {


    private final ZipMicroCourseHistoricalDataHandler zipMicroCourseHistoricalDataHandler;
    private final ZipMicroCourseV2HistoricalDataHandler zipMicroCourseV2HistoricalDataHandler;
    private final KnowledgeHistoricalDataHandler knowledgeHistoricalDataHandler;
    private final FileInfoHistoricalDataHandler fileInfoHistoricalDataHandler;
    private final BasicApplyUserIdHistoricalDataHandler basicApplyUserIdHistoricalDataHandler;
    private final BasicApplyTimeHistoricalDataHandler basicApplyTimeHistoricalDataHandler;
    private final BasicFileArchiveHistoricalDataHandler basicFileArchiveHistoricalDataHandler;
    private final BasicFileArchiveRollbackHistoricalDataHandler basicFileArchiveRollbackHistoricalDataHandler;
    private final BasicFileRestoreHistoricalDataHandler basicFileRestoreHistoricalDataHandler;
    private final FileEncryptDataHandler fileEncryptDataHandler;


    /**
     * 微课类型的资源，检查zip格式的文件，更新为mp4
     * @param parameter RequestParameter
     * @return Boolean
     */
    @PostMapping("/zip-micro-course")
    public HttpEntity<ObjectValueModel<Boolean>> zipMicroCourse(RequestParameter parameter) {
        zipMicroCourseHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 微课类型的资源，检查zip格式的文件，更新为mp4
     * @param parameter RequestParameter
     * @return Boolean
     */
    @PostMapping("/zip-micro-course-v2")
    public HttpEntity<ObjectValueModel<Boolean>> zipMicroCourseV2(RequestParameter parameter) {
        zipMicroCourseV2HistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }


    /**
     * 更新知识点，知识点层级发生变化后，需要更新es里面的层级
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/knowledge")
    public HttpEntity<ObjectValueModel<Boolean>> knowledge(RequestParameter parameter) {
        knowledgeHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 更新文件信息
     * 根据文件id，拉取最新的文件信息
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/file-info")
    public HttpEntity<ObjectValueModel<Boolean>> fileInfo(RequestParameter parameter) {
        fileInfoHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 更新应用者
     * 将历史应用者的id 更新为新的应用者
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/apply-user-id")
    public HttpEntity<ObjectValueModel<Boolean>> updateApplyUserId(RequestParameter parameter) {
        basicApplyUserIdHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 更新应用时间
     * #91503 历史资源的应用时间若为空值，则值统一刷为“首次创建日期、“首次创建时间-1h”～“首次创建时间”。不为空值的，不刷。
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/apply-time")
    public HttpEntity<ObjectValueModel<Boolean>> updateApplyTime(RequestParameter parameter) {
        basicApplyTimeHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 文件归档
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/file-archive")
    public HttpEntity<ObjectValueModel<Boolean>> fileArchive(RequestParameter parameter) {
        this.basicFileArchiveHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 回滚文件归档
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/rollback-file-archive")
    public HttpEntity<ObjectValueModel<Boolean>> rollbackFileArchive(RequestParameter parameter) {
        this.basicFileArchiveRollbackHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 解冻文件，让已归档的文件可以预览和下载
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/restore-file-archive")
    public HttpEntity<ObjectValueModel<Boolean>> restoreFileArchive(RequestParameter parameter) {
        this.basicFileRestoreHistoricalDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

    /**
     * 文件加密
     * @param parameter RequestParameter
     * @return ObjectValueModel
     */
    @PostMapping("/file-hls-encrypt")
    public HttpEntity<ObjectValueModel<Boolean>> fileHlsEncrypt(RequestParameter parameter) {
        this.fileEncryptDataHandler.handle(parameter);
        return ResponseEntity.ok(new ObjectValueModel<>(Boolean.TRUE));
    }

}
